package com.itheima.health.controller;

import com.itheima.health.entity.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@SuppressWarnings("ALL")
/**
 * @Description :全局异常处理
 * @author     :LD
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler
    public Result exceptionHandler(Exception e){
        //控制台打印异常信息
        e.printStackTrace();
        String msg=e.getMessage();
        if (msg.length()>200){
            return new Result(false,msg.substring(0,200));
        }else {
            return new Result(false,msg);
        }
    }
}
